﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Runtime.Serialization;

namespace CMD.BAL.CAT
{
   [DataContractAttribute]
   public class LeadTime
   {
       [DataMemberAttribute(EmitDefaultValue = false)]
       public int idLeadTime;
       [DataMemberAttribute(EmitDefaultValue = false)]
       public string transporte;
       //[DataMemberAttribute]
       //public string leadApoyo;
       public static DataTable GetData()
       {
            DataTable dt;
            //ejecutar store
            dt = CMD_WEB.DAL.SrvDB.ExecuteQuery("exec SP_CMD_CAT_SEL_LEADTIME");
            return dt;
       }
       public static List<LeadTime> GetDataLeadTime()
       {
           try
           {
                DataTable dt;
                dt = LeadTime.GetData();
                if (dt.Rows.Count == 0)
                {
                    return null;
                }
                else
                {
                    List<LeadTime> list = dt.AsEnumerable().Select(
                    row => new LeadTime
                    {
                        idLeadTime = row.Field<int?>("ID_LEADTIME").GetValueOrDefault(),
                        transporte = String.IsNullOrEmpty(row.Field<string>("TRANSPORTE"))
                        ? ""
                        : row.Field<string>("TRANSPORTE"),
                        //leadApoyo = String.IsNullOrEmpty(row.Field<string>(2))
                        //? ""
                        //: row.Field<string>(2),
                    }
                    ).ToList();
                    return list;
                }
           }
           catch (Exception ex)
           {

               throw ex;
           }
       }
       public LeadTime() 
       {
           idLeadTime = 0;
           transporte = "";
           //leadApoyo = "";
       }
       //public LeadTime(int idLeadTime, string terrestre, string leadApoyo)
       public LeadTime(int idLeadTime, string transporte)
       {
           this.idLeadTime = idLeadTime;
           this.transporte = transporte;
           //this.leadApoyo = leadApoyo;
       }
   }
}
